package com.hxd.otc.module.convenience.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.hxd.otc.R;
import com.hxd.otc.module.convenience.bean.ConvenienceBannerBean;
import com.hxd.otc.utils.GlideUtils;
import com.hxd.otc.utils.UIUtils;
import com.jude.rollviewpager.RollPagerView;

import java.util.ArrayList;

/**
 * 作  者 :  卫广玉
 * 时  间 :  2018/7/16 16:44
 * 描  述 :  ${便民服务Banner}
 */
public class ConvenienceBannerAdapter extends BaseLoopPagerAdapter {

    private ArrayList<ConvenienceBannerBean> mUrls = new ArrayList<>();

    public ConvenienceBannerAdapter(RollPagerView viewPager) {
        super(viewPager);
    }

    @Override
    public View getView(ViewGroup container, int position) {
        final ConvenienceBannerBean bannerBean = mUrls.get(position);
        View view = LayoutInflater.from(container.getContext()).inflate(R.layout.item_convenience_bannder, container, false);
        ImageView ivBanner = view.findViewById(R.id.iv_banner);
        GlideUtils.loadConvenienceBanner(container.getContext(), 3, UIUtils.getServiceImageUrlByPath(bannerBean.getBannerIcon()), ivBanner);
        ivBanner.setScaleType(ImageView.ScaleType.CENTER_CROP);
        view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mOnBannerClickListener != null) mOnBannerClickListener.onBannerClick(bannerBean);
            }
        });
        return view;
    }

    public void setNewData(ArrayList<ConvenienceBannerBean> data) {
        mUrls.clear();
        if (data != null) {
            mUrls.addAll(data);
        }
        notifyDataSetChanged();
    }

    @Override
    public int getRealCount() {
        return mUrls.size();
    }

    public ConvenienceBannerBean getItem(int positon) {
        return mUrls.get(positon);
    }

    private OnBannerClickListener mOnBannerClickListener;

    public void setOnBannerClickListener(OnBannerClickListener onBannerClickListener) {
        mOnBannerClickListener = onBannerClickListener;
    }

    public interface OnBannerClickListener {
        void onBannerClick(ConvenienceBannerBean convenienceBannerBean);
    }

}
